package p3as.cliente;

import java.awt.BorderLayout;
import java.awt.Dimension;
import javax.swing.JApplet;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;

public class Principal extends JApplet{
    
    private JDoubleBufferedCanvas jDoubleBufferedCanvas;
    private JButton finishButton;
    private JButton nextButton;
    private JPanel buttonPanel;
    private JTextField userText;
    private JLabel userLabel;
    private JLabel scoreLabel;
    private JTextField scoreText;
    
    @Override
    public void init(){
        
        this.setSize(500, 500);
        this.setVisible(true);
        
        jDoubleBufferedCanvas = new JDoubleBufferedCanvas();
        jDoubleBufferedCanvas.setSize(400, 400);
        jDoubleBufferedCanvas.setMaximumSize(new Dimension(400, 400));
        jDoubleBufferedCanvas.setMinimumSize(new Dimension(400, 400));
        jDoubleBufferedCanvas.setPreferredSize(new Dimension(400, 400));
        jDoubleBufferedCanvas.setVisible(true);
        
        this.add(jDoubleBufferedCanvas, BorderLayout.CENTER);
        
        buttonPanel = new JPanel();
        buttonPanel.setSize(new Dimension(400, 100));
        buttonPanel.setPreferredSize(new Dimension(400, 100));
        buttonPanel.setMaximumSize(new Dimension(400, 100));
        buttonPanel.setMinimumSize(new Dimension(400, 100));
        buttonPanel.setVisible(true);
        this.add(buttonPanel, BorderLayout.PAGE_END);
        
        finishButton = new JButton("Finish");
        finishButton.setSize(new Dimension(3,3));
        buttonPanel.add(finishButton, BorderLayout.WEST);
        
        nextButton = new JButton("Next");
        nextButton.setSize(new Dimension(3, 3));
        buttonPanel.add(nextButton, BorderLayout.EAST);
        
        userLabel = new JLabel("User: ");
        buttonPanel.add(userLabel, BorderLayout.SOUTH);
        
        userText = new JTextField("");
        userText.setSize(new Dimension(40, 20));
        userText.setPreferredSize(new Dimension(40, 20));
        userText.setMaximumSize(new Dimension(40, 20));
        userText.setMinimumSize(new Dimension(40, 20));
        buttonPanel.add(userText, BorderLayout.SOUTH);    
        
        scoreLabel = new JLabel("Score: ");
        buttonPanel.add(scoreLabel, BorderLayout.SOUTH);
        
        scoreText = new JTextField("");
        scoreText.setSize(new Dimension(40, 20));
        scoreText.setPreferredSize(new Dimension(40, 20));
        scoreText.setMaximumSize(new Dimension(40, 20));
        scoreText.setMinimumSize(new Dimension(40, 20));
        scoreText.setEditable(false);
        buttonPanel.add(scoreText, BorderLayout.SOUTH);    
    }

    public JDoubleBufferedCanvas getCanvas() {
        return jDoubleBufferedCanvas;
    }
    
    @Override
    public void start(){        
        SceneController sceneController = new SceneController(this);
        finishButton.addActionListener(sceneController);
        nextButton.addActionListener(sceneController);
        sceneController.execute();
    }

    public JTextField getFileText() {
        return userText;
    }

    public JTextField getUserText() {
        return userText;
    }

    public JTextField getScoreText() {
        return scoreText;
    }

    void paintRanking(Ranking ranking) {
        throw new UnsupportedOperationException("Not yet implemented");
    }
    
}
